<?php use_stylesheet('/enermaatik/tellimusevaade.css') ?>
<?php use_stylesheet('/enermaatik/arveldus.css') ?>
<div class="ccontentbox">
	<div class="ccontent">
<?php include_partial('basketPage/progress', array('node' => $node)) ?>
		<form action="<?php echo LinkGen::getInstance(LinkGen::STRUCTURE_ACTIONS)->link(null, array('module' => 'basketPage', 'action' => 'submitAddresses')) ?>" method="post">
		<div class="korvsisu">
			<?php include_partial('basketPage/userAddressBlock', array('label' => __('vali shipping addressi'),
				'addresses' => $shippingAddresses,
				'form' => $shippingAddressForm,
				'type' => 'shipping'
			)) ?>

			<?php include_partial('basketPage/userAddressBlock', array('label' => __('vali billing addressi'),
				'addresses' => $billingAddresses,
				'form' => $billingAddressForm,
				'type' => 'billing'
			)) ?>
		</div>
		<div class="tablebuttons">
			<div class="hallbutton">
				<div class="hallbuttonleft"><img src="/enermaatik/img/tbl.png" width="8" height="26" alt=""/></div>
				<div class="hallbuttoncenter">
					<p><a href="<?php echo __('epoodi_link') ?>"><?php echo __('jätka ostmist') ?></a></p>
				</div>
				<div class="hallbuttonright"><img src="/enermaatik/img/tbr.png" width="8" height="26" alt=""/></div>
				<div class="clear"></div>

			</div>
			<div class="button">
				<div class="buttonleft"><img src="/enermaatik/img/rbleft.png" width="8" height="26" alt=""/></div>
				<div class="buttoncenter">
					<p><a id="addresses_form_submit" href="#"><?php echo __('vormista ost') ?></a></p>
				</div>
				<div class="buttonright"><img src="/enermaatik/img/rbr.png" width="8" height="26" alt=""/></div>
				<div class="clear"></div>

			</div>
			<div class="clear"></div>
		</div>
		</form>
	</div>
</div>

<?php use_stylesheet('/js/prompt/style.css') ?>
<?php use_javascript('/js/prompt/scripts.js') ?>
<script type="text/javascript">

$('#addresses_form_submit').click(function(e){
	e.preventDefault();

	var form = $(this).parents('form');
	var flash = '<h1>Fill form correctly</h1>';

	$.post(form.attr('action'), form.serialize(), function(data){
		if(data.status == 200){
			window.location = data.redirect;
		}else{
			for(formMsg in data.messages){
				flash = flash + "<h2>" + formMsg + "</h2>";
				for(msg in data.messages[formMsg]){
					flash = flash + data.messages[formMsg][msg] + "<br />";
				}
			}

			$.prompt(flash,{
				buttons: { OK:true }
			});

		}
	},'json');


	return false;
});

$('.edit_address').click(function(e){
	e.preventDefault();

	var link = $(this);
	var formFieldsContainer = link.parents('.address_block').find('.address_block_form');
	// get form, put into right place
	$.post('<?php echo LinkGen::getInstance(LinkGen::STRUCTURE_ACTIONS)->link(null, array('module' => 'basketPage', 'action' => 'getForm')) ?>', {address: $(this).attr('href')}, function(data){
		formFieldsContainer.html(data.formHTML);
	}, 'json');

	return false;
});

$('.radio').click(function(){
$('.radio').removeClass("active");
$(this).addClass("active");
});
</script>
<script type="text/javascript">
  $('#billing_same').click(function() {
    if($('#billing_same').is(':checked')) {
      $('#billing_address_name').val($('#shipping_address_name').val());
      $('#billing_address_address').val($('#shipping_address_address').val());
      $('#billing_address_phone').val($('#shipping_address_phone').val());
      $('#billing_address_city').val($('#shipping_address_city').val());
      $('#billing_address_country').val($('#shipping_address_country').val());
      $('#billing_address_state').val($('#shipping_address_state').val());
      $('#billing_address_zip').val($('#shipping_address_zip').val());
    }
  });
</script>